home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Utilities / XPK / xpk_Source / xpkmaster / query.c < prev    next >
C/C++ Source or Header  |  1999-09-08  |  5KB  |  193 lines

  1. #ifndef XPKMASTER_QUERY_C
  2. #define XPKMASTER_QUERY_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        query.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: query.c 1.12 (08.09.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Implementation of XpkQuery
  12.  
  13.  1.0   06.10.96 : first real version
  14.  1.1   27.12.96 : removed 1.3 specific functions
  15.  1.2   09.03.97 : added USER mode
  16.  1.3   31.03.97 : made tag processing better, nearly rewritten all, removed
  17.      goto's this way
  18.  1.4   09.06.97 : fixed Enforcer hit, when library opening failed
  19.  1.5   19.12.97 : code cleanup
  20.  1.6   24.12.97 : no packmode brings default mode now
  21.  1.7   01.01.98 : USER information is a bit better now
  22.  1.8   21.02.98 : uses new style register definition
  23.  1.9   03.03.98 : fixed enforcer hits
  24.  1.10  26.03.98 : some optimizations
  25.  1.11  29.04.98 : fixed bug (compiler problem)
  26.  1.12  08.09.99 : shorten names longer than XpkPackerInfo fields
  27. */
  28.  
  29. #include <exec/memory.h>
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/xpksub.h>
  33. #include <proto/utility.h>
  34. #include "xpkmaster.h"
  35. #include "texts.h"
  36.  
  37. /************************************************************************
  38.  *
  39.  *  Information query
  40.  *
  41.  */
  42.  
  43. static const struct XpkMode USERMode = { 0,100,0,0,0,50,500,500,0,"user"};
  44.  
  45. static struct XpkInfo USERInfo = { 1,0,0,1,"USER","User",
  46. 0, 0x55534552, XPKIF_PK_CHUNK|XPKIF_UP_CHUNK, DEFAULTCHUNKSIZE, 10,
  47. DEFAULTCHUNKSIZE,0,0,0,0,100,0,&USERMode,0,0,0,0,0,0};
  48.  
  49. ASM(LONG) LIBXpkQuery(REG(a0, struct TagItem *tags))
  50. {
  51.   struct TagItem    *ti, *ti2 = tags;
  52.   ULONG            packmode = 101,
  53.             packmethod = 0,
  54.               prefs = 1; /* use prefs, default is true */
  55.   LONG            error = 0;
  56.   struct XpkPackerInfo *pinfo = 0;
  57.   struct XpkPackerList *plist = 0;
  58.   struct XpkMode *    pmode = 0;
  59.   struct Library *    XpkSubBase = 0;
  60.   struct XpkInfo *    sinfo = 0;
  61.   UBYTE            libname[SUBLIBNAME_SIZE];
  62.  
  63. #ifdef DEBUG
  64.   DebugTagList("XpkQuery", tags);
  65. #endif
  66.  
  67.   while((ti = NextTagItem(&ti2)))
  68.   {
  69.     switch(ti->ti_Tag)
  70.     {
  71.     case XPK_PackersQuery: plist = (struct XpkPackerList *) ti->ti_Data;
  72.       break;
  73.     case XPK_ModeQuery: pmode = (struct XpkMode *) ti->ti_Data; break;
  74.     case XPK_PackerQuery: pinfo = (struct XpkPackerInfo *) ti->ti_Data;
  75.       break;
  76.     case XPK_PackMethod: packmethod = idfromname((STRPTR) ti->ti_Data);
  77.       break;
  78.     case XPK_PackMode: packmode = ti->ti_Data; break;
  79.     case XPK_Preferences: prefs = ti->ti_Data; break;
  80.     }
  81.   }
  82.  
  83.   if(plist)
  84.   {
  85.     struct FileInfoBlock *fib;
  86.  
  87.     if(!(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)))
  88.       error = XPKERR_NOMEM;
  89.     else
  90.     {
  91.       ULONG lock;
  92.  
  93.       memset(plist, 0, sizeof(struct XpkPackerList));
  94.       if(!(lock = Lock("LIBS:compressors", ACCESS_READ)))
  95.         error = XPKERR_NOINFO;
  96.       else
  97.       {
  98.         if(!Examine(lock, fib) || fib->fib_DirEntryType < 0)
  99.           error = XPKERR_NOINFO;
  100.         else
  101.         {
  102.       while(ExNext(lock, fib))
  103.       {
  104.         if(!strncmp("xpk", fib->fib_FileName, 3) &&
  105.             !strcmp(".library", fib->fib_FileName+7))
  106.         {
  107.           ULONG ID = idfromname(fib->fib_FileName+3), i;
  108.  
  109.               for(i = plist->xpl_NumPackers; i > 0 &&
  110.           *(ULONG *) plist->xpl_Packer[i - 1] > ID; i--)
  111.           *(ULONG *) plist->xpl_Packer[i] =
  112.           *(ULONG *) plist->xpl_Packer[i-1];
  113.           *(ULONG *) plist->xpl_Packer[i] = ID;
  114.  
  115.           if(++plist->xpl_NumPackers == MAXPACKERS)
  116.             break;
  117.         }
  118.       }
  119.           if(prefs) /* add USER mode */
  120.           {
  121.         if(plist->xpl_NumPackers == MAXPACKERS)
  122.           --plist->xpl_NumPackers;
  123.             *(ULONG *) plist->xpl_Packer[plist->xpl_NumPackers++] = USER_COOKIE;
  124.           }
  125.         }
  126.         UnLock(lock);
  127.       }
  128.       FreeDosObject(DOS_FIB, fib);
  129.     }
  130.   }
  131.   else if(packmethod)
  132.   {
  133.     if(packmethod == USER_COOKIE)
  134.     {
  135.       sinfo = &USERInfo;
  136.       sinfo->xi_Description = strings[TXT_USER_DESCRIPTION];
  137.     }
  138.     else
  139.     {
  140.       sprintf(libname, SUBLIBNAME_STRING, &packmethod);
  141.  
  142.       if(!(XpkSubBase = OpenLibrary(libname, 0)) ||
  143.       !(sinfo = XpksPackerInfo()))
  144.         error = XPKERR_MISSINGLIB;
  145.     }
  146.     
  147.     if(!error)
  148.     {
  149.       if(pinfo)
  150.       {
  151.         sprintf(pinfo->xpi_Name, "%.23s", sinfo->xi_Name);
  152.         sprintf(pinfo->xpi_LongName, "%.31s", sinfo->xi_LongName);
  153.         sprintf(pinfo->xpi_Description, "%.79s", sinfo->xi_Description);
  154.         pinfo->xpi_Flags = sinfo->xi_Flags;
  155.         pinfo->xpi_MaxChunk = sinfo->xi_MaxPkInChunk;
  156.         pinfo->xpi_DefChunk = sinfo->xi_DefPkInChunk;
  157.         pinfo->xpi_DefMode = sinfo->xi_DefMode;
  158.       }
  159.       else if(pmode)
  160.       {
  161.         struct XpkMode* m = sinfo->xi_ModeDesc;
  162.  
  163.         if(packmode == 101)
  164.           packmode = sinfo->xi_DefMode;
  165.  
  166.         while(m && m->xm_Upto < packmode)
  167.           m = m->xm_Next;
  168.  
  169.         if(m)
  170.         {
  171.           CopyMem(m, pmode, sizeof(struct XpkMode));
  172.           pmode->xm_Description[9] = 0; /* force C-string for these dumb persons,
  173.                           which cannot count (e.g. Niels Froehling) */
  174.           pmode->xm_Next = 0;
  175.         }
  176.         else
  177.           error = XPKERR_NOINFO;
  178.       }
  179.       else
  180.         error = XPKERR_BADPARAMS;
  181.     }
  182.     if(XpkSubBase)
  183.       CloseLibrary(XpkSubBase);
  184.   }
  185.   else
  186.     error = XPKERR_BADPARAMS;
  187.  
  188.   return parseerrortags(tags, error);
  189. }
  190.  
  191. #endif /* XPKMASTER_QUERY_C */
  192.  
  193.